const defaultState = {
    loading: false,
    dataSource: [],
    clientList: [],
    carrierList: [],
    currencyList: [],
    businessCodeList: [],
    selectedRowKeys: [],
    transportTypeList: [],
    coachList: [],
    page: 1,
    pageSize: 20,
    totalElements: 0,
    openFollow: false,
    orderDaiBan: "",
    filter: {},
    importLoading: false
};
export default function list(state = defaultState, action) {
    const {type, payload, error} = action;
    switch (type) {

        case 'ZAD_ORDER.QUERY':
            if (error === true) {
                return {...state, loading: false};
            }
            return {
                ...state,
                loading: false,
                dataSource: payload.content,
                page: payload.page,
                pageSize: payload.pageSize,
                totalElements: payload.totalElements,
                selectedRowKeys: []
            };
        case 'ZAD_ORDER.QUERY_PENDING':
            if (error === true) {
                return {...state, loading: false};
            }
            return {
                ...state, filter: {...payload}
            };
        case 'ZAD_ORDER.GET_CLIENT':
            return {...state, clientList: [...payload]};
        case 'ZAD_ORDER.GET_CARRIER':
            return {...state, carrierList: [...payload]};
        case 'ZAD_ORDER.GET_CURRENCY':
            return {...state, currencyList: [...payload]};
        case 'ZAD_ORDER.LOCK':
            return {...state, selectedRowKeys: []};
        case 'ZAD_ORDER.UN_LOCK':
            return {...state, selectedRowKeys: []};
        case 'ZAD_ORDER.GET_BUSINESS_CODE_LIST':
            return {...state, businessCodeList: [...payload]};
        case 'ZAD_ORDER.GET_TRANSPORT_TYPE':
            return {...state, transportTypeList: [...payload]};
        case 'ZAD_ORDER.GET_COACH_LIST':
            return {...state, coachList: [...payload]};
        case 'ZAD_ORDER.UPDATE_DATA_SOURCE':
            return {...state, dataSource: [...payload]};
        case 'ZAD_ORDER.SELECT':
            return {...state, selectedRowKeys: payload};
        case 'ZAD_ORDER.OPEN_FOLLOW':
            return {...state, openFollow: payload};
        case 'ZAD_ORDER.IMPORT_PENDING':
            return {...state, importLoading: true};
        case 'ZAD_ORDER.IMPORT':
            return {...state, importLoading: false};
        default:
            return state;
    }
}

